﻿using GalaSoft.MvvmLight;

namespace Budgetsch.WP7.ViewModel.Public
{
    using System;
    using System.Collections.ObjectModel;
    using System.Data.Services.Client;

    using Budgetsch.WP7.Navigation;
    using Budgetsch.WP7.ViewModel.Income;
    using Budgetsch.WP7.WP7DataService;

    using GalaSoft.MvvmLight.Ioc;
    using GalaSoft.MvvmLight.Messaging;

    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class PublicUserViewModel : ViewModelBase
    {
        private readonly INavigationService _navigationService;

        /// <summary>
        /// The <see cref="User" /> property's name.
        /// </summary>
        public const string UserPropertyName = "User";

        private User _user;

        /// <summary>
        /// Sets and gets the User property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public User User
        {
            get
            {
                return _user;
            }

            set
            {
                if (_user == value)
                {
                    return;
                }

                _user = value;
                RaisePropertyChanged(UserPropertyName);
            }
        }

        /// <summary>
        /// Initializes a new instance of the PublicUserViewModel class.
        /// </summary>
        /// <param name="user"></param>
        public PublicUserViewModel(User user, INavigationService navigationService)
        {
            _navigationService = navigationService;
            User = user;
        }

        public void NavigateToDetailsView()
        {
            SimpleIoc.Default.GetInstance<PublicDashboardViewModel>();
            Messenger.Default.Send(new LoadPublicDashboardViewMessage { User = User });

            SimpleIoc.Default.GetInstance<CommentWriterViewModel>();
            Messenger.Default.Send(new AddToUserNameMessage { UserName = User.UserName });
            _navigationService.NavigateTo(new Uri("/View/PublicDashboardView.xaml", UriKind.Relative));
        }
    }
}